package org.learnredis;

import org.learnredis.dataReaders.StudentReader;
import org.learnredis.dataReaders.UniversityReader;
import org.learnredis.student.Student;
import org.learnredis.student.StudentComparator;
import org.learnredis.student.StudentComparators;
import org.learnredis.university.University;
import org.learnredis.university.UniversityComparator;
import org.learnredis.university.UniversityComparators;
import org.learnredis.utils.ProjectComparators;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.stream.Stream;

public class Main {
    private static final Logger logger = LoggerFactory.getLogger(Main.class);

    public static void main(String[] args) {
        String timeStamp = new SimpleDateFormat("dd-MM-yyyy : HH-mm-ss").format(Calendar.getInstance().getTime());
        logger.info(String.format("app start with: %s", timeStamp));

        ArrayList<Student> studentList = new ArrayList<Student>();
        ArrayList<University> universityList = new ArrayList<University>();

        try {
            studentList = StudentReader.fileRead();
            universityList = UniversityReader.fileRead();
        } catch (IOException e) {
            logger.error(Arrays.toString(e.getStackTrace()));
        }

        System.out.println("Student list");
        StudentComparator avgComparator = ProjectComparators.getComparator(StudentComparators.AVG_EXAM_SCORE);
        StudentComparator currentCourseComparator = ProjectComparators.getComparator(StudentComparators.CURRENT_COURSE);
        StudentComparator fullNameComparator = ProjectComparators.getComparator(StudentComparators.FULL_NAME);

        System.out.println("avgComparator");
        assert avgComparator != null;
        studentList.stream().sorted(avgComparator).forEach(System.out::println);
        System.out.println("---");

        System.out.println("currentCourseComparator");
        assert currentCourseComparator != null;
        studentList.stream().sorted(currentCourseComparator).forEach(System.out::println);
        System.out.println("---");

        System.out.println("fullNameComparator");
        assert fullNameComparator != null;
        studentList.stream().sorted(fullNameComparator).forEach(System.out::println);
        System.out.println("---");

        System.out.println();

        System.out.println("University list");

        UniversityComparator fullNameComparatorUniversity = ProjectComparators.getComparator(UniversityComparators.FULL_NAME);
        UniversityComparator shortNameComparatorUniversity = ProjectComparators.getComparator(UniversityComparators.SHORT_NAME);
        UniversityComparator yearOfFoundationComparatorUniversity = ProjectComparators.getComparator(UniversityComparators.YEAR_OF_FOUNDATION);
        UniversityComparator mainProfileComparatorUniversity = ProjectComparators.getComparator(UniversityComparators.STUDY_PROFILE);

        System.out.println("fullNameComparator");
        assert fullNameComparatorUniversity != null;
        universityList.stream().sorted(fullNameComparatorUniversity).forEach(System.out::println);
        System.out.println("---");

        System.out.println("shortNameComparatorUniversity");
        assert shortNameComparatorUniversity != null;
        universityList.stream().sorted(shortNameComparatorUniversity).forEach(System.out::println);
        System.out.println("---");

        System.out.println("yearOfFoundationComparatorUniversity");
        assert yearOfFoundationComparatorUniversity != null;
        universityList.stream().sorted(yearOfFoundationComparatorUniversity).forEach(System.out::println);
        System.out.println("---");

        System.out.println("mainProfileComparatorUniversity");
        assert mainProfileComparatorUniversity != null;
        universityList.stream().sorted(mainProfileComparatorUniversity).forEach(System.out::println);
        System.out.println("---");
    }
}
